package controllers;

import java.awt.event.ActionEvent;
import java.io.IOException;

import ccrm.BoundryControl;
import ccrm.ClientMain;
import entitys.Customer;
import entitys.Request;
import entitys.Session;
import enums.Command;
import enums.Result;

public class UpdateClientController {

	/**
	 * Method for creating a request for server.
	 * Gets all the fields needed for updating a customer and sends a request to server.
	 */
	public static Result updateClient(String id,String fname,String lname,String email,String phone,String address,boolean permit,String birth)
	{
		Request r =	new Request(Command.UPDATE_CLIENT,Session.getEmployee().getUserId(),new Customer(fname,lname,address,phone,email,id,permit,birth));

		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return Result.OK;
	}

	/**
	 * Method for creating a request for server.
	 * Gets all the customers in database.
	 */
	public static void getClients() 
	{
		Request r =new Request(Command.GET_CLIENTS,Session.getEmployee().getUserId());


		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/**
	 * Method for creating a request for server.
	 * Gets all the external customers in database.
	 */
	public static void getExternalClients() {

		Request r =new Request(Command.GET_EXTERNAL_CLIENTS,Session.getEmployee().getUserId());


		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
